// @ts-ignore
import {request} from 'umi';
import {convertProSort} from '@/utils/utils';

// 获取品种枚举
export const getVarietys = () => request('/api/cats/varietys', {
    method: 'GET'
});

// 获取猫咪列表
export const getList = async (params, sorter) => {
    const sortParams = convertProSort(sorter);
    const {pageSize, current} = params;
    const formatParams = {
        ...params,
        ...sortParams,
        pager: {
            pageSize,
            current
        }
    };
    Reflect.deleteProperty(formatParams, 'pageSize');
    Reflect.deleteProperty(formatParams, 'current');
    const res = await request('/api/cats', {
        method: 'POST',
        data: formatParams
    });
    const {code, data, pager} = res || {};
    return {
        success: code === 0,
        data: data?.list || [],
        total: pager?.total
    };
};

export const saveItem = (params = {}) => request('/api/cats/save', {
    method: 'POST',
    data: {
        ...params,
    },
});

export function delItem(id) {
    return request(`/api/cats/${id}`, {
        method: 'DELETE',
    });
}

